<%@ page contentType="text/html;charset=UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html>
<html lang="en">
<head>
<%@ include file="/common/common-css.v2.jsp"%>
<style>
#jquery-table td {
	cursor: pointer !important;
	word-break: break-all;
	word-wrap: break-word;
}

.load_bg {
	background: #000;
	opacity: 0.1;
	left: 0px;
	top: 0px;
	position: fixed;
	height: 100%;
	width: 100%;
	overflow: hidden;
	z-index: 10000;
}

.load_img {
	left: 50%;
	top: 180px;
	position: fixed;
	height: 50px;
	overflow: hidden;
	z-index: 20000;
}

a.check {
	margin-bottom: 10px;
}

@media ( min-width : 468px) and (max-width: 900px) {
	.backup-text {
		width: 100px !important;
	}
}
</style>
</head>
<body >
	<div class="load_bg" style="display: none;"></div>
	<img src="http://img.xmiles.cn/commentloading.gif" class="load_img"
		style="display: none" />
	<div class="page-content">
		
			<div class="page-content-area">
								<div class="row">
									<div class="form-group col-xs-7 ">
										<label class="col-sm-4 control-label">商户名:</label>
										<div class="input-group col-sm-8">
											<input type="text" class="form-control" name="name"
												id="name-code" style="margin-bottom: 5px">
										</div>

										<label class="col-sm-4 control-label">商户账号:</label>
										<div class="input-group col-sm-8">
											<input type="text" class="form-control" name="userid"
												id="userid-code" style="margin-bottom: 5px">
										</div>

										<label class="col-sm-4 control-label">总金额:</label>
										<div class="input-group col-sm-8">
											<input type="text" class="form-control" name="total"
												id="total-code" style="margin-bottom: 5px">
										</div>
										<label class="col-sm-4 control-label">单价:</label>
										<div class="input-group col-sm-8">
											<input type="text" class="form-control" name="unitPrice"
												id="unitPrice-code" style="margin-bottom: 5px">
										</div>
										<label class="col-sm-4 control-label">余额:</label>
										<div class="input-group col-sm-8">
											<input type="text" class="form-control" name="balance"
												id="balance-code" style="margin-bottom: 5px">
										</div>
										<label class="col-sm-4 control-label">创建时间:</label>
										<div class="input-group col-sm-8">
											<input type="text" data-date-format="yyyy-mm-dd"
												class="date-picker input-sm form-control" id="date-code"
												style="margin-bottom: 5px" name="date">
										</div>
										<div class="ad-from"></div>
										<label class="col-sm-4 control-label">URL:</label>
										<div class="input-group col-sm-2"></div>
										<div class="input-group col-sm-6">
											<button class=" btn-primary btn-sm glyphicon glyphicon-plus"
												id="addUrl" style="margin-left: 6px;"></button>
										</div>
									</div>
								</div>
							
								<textarea name="url" id="url-code" style="margin: 0px; width: 800px; height: 60px;">
								</textarea>
								
								
							<div class="modal-footer">
								<button type="button" class="btn btn-default"
									data-dismiss="modal" id="back">取消</button>
								<button type="button" class="btn btn-primary" id="change">确认</button>
							</div>
						
			</div>
	</div>
	<!-- /.page-content -->





	<%@ include file="/common/common-js.jsp"%>
	
	
	<script type="text/javascript" src="${ctx}/js/call_func.js"></script>

	<script type="text/javascript">
		//接受URL参数，进行文档写入
		function getQueryString(name) {
			var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
			var r = window.location.search.substr(1).match(reg);
			if (r != null)
				return decodeURI(r[2]);
			return null;
		}
		
		jQuery(function($) {
			//渲染表单数据
			$('#userid-code').val(getQueryString("userid")==null?"":getQueryString("userid"));
			$('#url-code').val(getQueryString("url")=="null"?"":getQueryString("url"));				
			$('#name-code').val(getQueryString("name"));
			$('#unitPrice-code').val(getQueryString("unitPrice"));
			$('#total-code').val(getQueryString("total"));
			$('#balance-code').val(getQueryString("balance"));
			var now = new Date().getFullYear()+"-"+(Number(new Date().getMonth())+1)+"-"+new Date().getDate();
			var id=(getQueryString("id")==null?"null":getQueryString("id"));
			$('#date-code').val(getQueryString("date")==null?now:getQueryString("date"));
			if(id!="null"){
				$('.ad-from').append("<label class='col-sm-4 control-label'>增加金额:</label>"+
				"<div class='input-group col-sm-8'>"+
					"<input type='text' class='form-control' name='addmoney'"+
						"id='addmoney-code' style='margin-bottom: 5px'>"+
				"</div>");
			}			
			
			//输入金额后自动显示余额等于金额
			$('#total-code').change(function() {
				var balance = $('#balance-code').val();
				var total = $('#total-code').val();
				$('#balance-code').val(Number(total));
			});
			
			//时间显示插件
			$(".date-picker").datepicker({
				autoclose : true
			}).next().on(ace.click_event, function() {
				$(this).prev().focus();
			});
			
			//添加;作为url分割				
			$("#addUrl").on('click', function() {
				var url = $('#url-code').val();	
				if(url.substring(url.length-1,url.length)!=';'){
					$('#url-code').val(url + ';');
				}
			});
			
			$('#back').on('click',function(){
				parent.parent['__extdialog_active'].dialog('close');
			});
			
			//增加修改
			$('#change').on(
					'click',
					function() {
						var name = $('#name-code').val();
						var unitPrice = $('#unitPrice-code').val();
						var total = $('#total-code').val();
						var balance = $('#balance-code').val();
						var date = $('#date-code').val();
						var dateurl = $('#url-code').val();
						var addmoney = $("#addmoney-code").val();
						var userid = $('#userid-code').val();
						var url= ctx + "/spread/"+(id=="null"?"gg_adAdd.action":"gg_adEdit.action");	
						if (name != '' && name != null) {
							$.ajax({
								"type" : "POST",
								"dataType" : 'json',
								"url" : url,
								"data" : {
									"id" : id,
									"name" : name,
									"unitPrice" : unitPrice,
									"total" : total,
									"balance" : balance,
									"date" : date,
									"userid" : userid,
									"url" : dateurl,
									"addmoney" : addmoney
								},
								"success" : function(resp) {
									parent.parent['__extdialog_active'].dialog('close');
									parent.main_frame.query_any();	
								},
								"error" : function(XMLHttpRequest, textStatus,
										errorThrown) {
									alert(textStatus);
								}
							});
						} else {
							$('#name-code').focus();
						}
					});

		});
	</script>

</body>
</html>